﻿using Assets.Script.NetSystem.Battle.Core;
using Assets.Script.NetSystem.Services.RoomAndBattle.HallService.Handler;
using LiteNetLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _2DGame_Preview_Server.Services.RoomAndBattle.RoomHall.Model;
using Newtonsoft.Json;
using Script.NetSystem.Core;
using SimpleTools.Json;
using SimpleTools.Net.SimpleServer.UDP;
using UnityEngine;

namespace Assets.Script.NetSystem.Services.HallService
{
    public class HallClient : BaseClient<HallClient, IHallHandler>
    {
        public HallClient(int prot, string userKey, ConnectSuccess onConnectSuccess) : base(prot, userKey, onConnectSuccess)
        {
            
        }

        protected override Type[] GetHandlerTypes()
        {
            return new[] {typeof(JoinRoom)};
        }

        protected override HallClient GetThisClient()
        {
            return this;
        }

        public void CreateRoom()
        {
            JsonData jsonData = new JsonData("createroom");
            jsonData.Add("case", "Case01");
            client.Send(jsonData);
        }

        public void JoinRoom(RoomInfo roomInfo)
        {
            JsonData jsonData = new JsonData("joinroom");
            jsonData.Add("roomInfo", roomInfo);
            ClientSend(jsonData);
        }

        public void GetRoomsList(string caseName)
        {
            JsonData jsonData = new JsonData("getrooms");
            jsonData.Add("case", caseName);
            client.Send(jsonData);
        }

        public void ClientStop()
        {
            client.Stop();
        }
        

    }
}
